import { type RouteRecordItem, basicRoutes } from 'vc/src/router';

/** 404 具体页面标题 */
export const PAGE_NOT_FOUND_NAME = 'PageNotFound';

export const LINK_HOME = '/';
export const LINK_LOGIN = '/login';
export const LINK_REG = '/register';
export const LINK_FORGOT = '/forgot';
export const LINK_ERROR = '/exception';
export const LINK_AGREEMENT_USER = '/agreement/user';
export const LINK_AGREEMENT_PRIVACY = '/agreement/privacy';

export const LAYOUT = () => import('@/layouts/index.vue');
// 用户相关页面
export const LOGIN_PAGE = () => import('@/views/user/login/index.vue');
export const REG_PAGE = () => import('@/views/user/reg/index.vue');
export const FORGOT_PAGE = () => import('@/views/user/forgot/index.vue');
export const AGREEMENT_USER_PAGE = () => import('@/views/user/agreement/user.vue');
export const AGREEMENT_PRIVACY_PAGE = () => import('@/views/user/agreement/privacy.vue');

export const ERROR_PAGE = () => import('@/views/sys/error-log/index.vue');
export const HOME_PAGE = () => import('@/views/home/index.vue');
export const EXCEPTION_COMPONENT = () => import('@/views/sys/exception/Exception.vue');

const { RootRoute, LOGIN_ROUTE, FORGOT_ROUTE, REG_ROUTE, PAGE_NOT_FOUND_ROUTE, ERROR_LOG_ROUTE } = basicRoutes({
  baseLayout: LAYOUT,
  rootCfg: { children: [{ component: HOME_PAGE }], meta: { hideSide: true, scrollDom: '.home' } },
  loginCfg: { component: LOGIN_PAGE, path: LINK_LOGIN },
  forgotCfg: { component: FORGOT_PAGE, path: LINK_FORGOT },
  regCfg: { component: REG_PAGE, path: LINK_REG },
  notFoundCfg: {
    name: PAGE_NOT_FOUND_NAME,
    children: [{ name: PAGE_NOT_FOUND_NAME, component: EXCEPTION_COMPONENT }]
  },
  errorCfg: { children: [{ component: ERROR_PAGE }] },
  exceptionCfg: { children: [{ component: ERROR_PAGE }] }
});

export { PAGE_NOT_FOUND_ROUTE, ERROR_LOG_ROUTE };

// 可以无需 token 校验的页面
export const mainOutRoutes: RouteRecordItem[] = [
  {
    path: LINK_AGREEMENT_USER,
    component: AGREEMENT_USER_PAGE,
    meta: {
      title: '用户协议'
    }
  },
  {
    path: LINK_AGREEMENT_PRIVACY,
    component: AGREEMENT_PRIVACY_PAGE,
    meta: {
      title: '隐私政策'
    }
  }
];

// 登录注册相关页面
export const USER_WRAPPER_PAGE_LIST = [LINK_LOGIN, LINK_REG, LINK_FORGOT];

/** 白名单页面路径 */
export const WHITE_NAME_LIST: string[] = [...USER_WRAPPER_PAGE_LIST, LINK_AGREEMENT_USER, LINK_AGREEMENT_PRIVACY];

export const NOT_IN_TABS_LIST: string[] = [...USER_WRAPPER_PAGE_LIST, LINK_AGREEMENT_USER, LINK_AGREEMENT_PRIVACY];

/**
 * @description 基础路由
 */
export const routes = [RootRoute, LOGIN_ROUTE, REG_ROUTE, FORGOT_ROUTE, PAGE_NOT_FOUND_ROUTE, ...mainOutRoutes];
